#include "myjsb/Goddess.h"
#include <cstdlib>
#include <ctime>

namespace cocos2d { namespace myjsb {

    Goddess* Goddess::_instance = nullptr;    // 必须写，否则报错“无法解析的外部符号”。

    Goddess* Goddess::getInstance()
    {
        if (_instance == nullptr)
        {
            _instance = new Goddess();
        }

        return _instance;
    }

    void Goddess::destroyInstance()
    {
        CC_SAFE_DELETE(_instance);
    }

    std::string Goddess::sayHi() {
        std::string s = "Hi! Cutie~";

        return s;
    }

    void Goddess::receiveGift(Gift& gift, const ResultCallback& callback) {
        std::string txts[] = {"What is this?", "Just so so.", "That's great!"};
        std::string s = gift.getName();
        int k = 0;
        int v = 0;

        if (s.empty()) {
            s += txts[0];
            v = -10;
        } else {
            srand((int)time(0));  // 产生随机种子  把0换成NULL也行
            k = (rand() % ((sizeof(txts) / sizeof(txts[0])) - 1)) + 1;
            v = ((rand() % 10) + 1);

            if (1 == k) {
                v *= -1;
            }

            s = s + ", " + txts[k];
        }

        if (callback) {
            callback(s, v);
        }
    }
    
}}  //  namespace cocos2d::myjsb
